﻿using System.Windows;

namespace Red.Core
{
    /// <summary>
    /// Simplifying usage of system's Clipboard. No serialization of data object required. Data object is stored in this class instead of Clipboard.
    /// For validation purpose string with data object type name is stored in Clipboard.
    /// </summary>
    public static class RedClipboard
    {
        #region Data

        private static object _dataObject;
        private static string _objectType;

        #endregion Data

        #region Public methods

        public static void SetData( object dataObject )
        {
            _objectType = dataObject.GetType().FullName;
            Clipboard.SetData( _objectType, _objectType );

            _dataObject = dataObject;
        }

        public static bool ContainsData<T>()
        {
            return _dataObject != null && Clipboard.ContainsData( typeof( T ).FullName );
        }

        public static object GetData()
        {
            if ( Clipboard.ContainsData( _objectType ) )
                return _dataObject;

            return null;
        }

        #endregion Public methods
    }
}
